package li.nibble.twittertido;

import li.nibble.twittertido.adapter.SectionsPagerAdapter;
import li.nibble.twittertido.fragment.TweetSectionFragment;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;

public class Main extends FragmentActivity {

	SectionsPagerAdapter mSectionsPagerAdapter;

	ViewPager mViewPager;

	private GestureDetector gestureDetector;
	public View.OnTouchListener gestureListener;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		mSectionsPagerAdapter = new SectionsPagerAdapter(
				getApplicationContext(), getSupportFragmentManager());
		mViewPager = (ViewPager) findViewById(R.id.pager);
		mViewPager.setAdapter(mSectionsPagerAdapter);

		gestureDetector = new GestureDetector(new UpGestureDetector());
		gestureListener = new View.OnTouchListener() {
			public boolean onTouch(View v, MotionEvent event) {
				if (gestureDetector.onTouchEvent(event)) {
					return true;
				}
				return false;
			}
		};
		mViewPager.setOnTouchListener(gestureListener);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	class UpGestureDetector extends SimpleOnGestureListener {

		private static final int SWIPE_MIN_DISTANCE = 120;

		@Override
		public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
				float velocityY) {
			try {
				if (e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE) {
					Log.e("adfad", "adsfadsf");
				} else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE) {
					Log.e("adfad", "regweg");
				}

			} catch (Exception e) {
				Log.e("adfad", "dfasdfa");
			}
			return false;
		}
	}

}
